package com.asktgapp.widget;
import android.content.Context;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.asktgapp.R;
import com.asktgapp.model.NewHomeOneBean;
import com.asktgapp.user.activity.EngineerDetailActivity;
import com.asktgapp.user.activity.EngineerListActivity;
import com.asktgapp.user.activity.HomeServiceActivity;
import com.asktgapp.user.activity.HomeServiceDetailActivity;
import com.asktgapp.user.activity.IndurstryInformationActivity;
import com.asktgapp.user.activity.IndustryInfoDetailActivity;
import com.asktgapp.user.activity.NewWebActivity;
import com.asktgapp.user.activity.RentDetailActivity;
import com.asktgapp.user.activity.RentMachineNewActivity;
import com.asktgapp.user.activity.UsedMachineDetailActivity;
import com.asktgapp.user.activity.UsedSecondhandTypeActivity;
import com.sobot.chat.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;


public class JDViewAdapter {
    private List<NewHomeOneBean.NewsPaperBean> mDatas;
    private Context context;

    public void setmDatas(List<NewHomeOneBean.NewsPaperBean> mDatas) {
        this.mDatas = mDatas;

    }

    public JDViewAdapter(List<NewHomeOneBean.NewsPaperBean> mDatas, Context context) {
        this.mDatas = mDatas;
        this.context = context;
        if (mDatas == null || mDatas.isEmpty()) {
            throw new RuntimeException("nothing to show");
        }
    }
    /**
     * 获取数据的条数
     * @return
     */
    public int getCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    /**
     * 获取摸个数据
     * @param position
     * @return
     */
    public NewHomeOneBean.NewsPaperBean getItem(int position) {
        return mDatas.get(position);
    }
    /**
     * 获取条目布局
     * @param parent
     * @return
     */
    public View getView(JDAdverView parent) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.jd_adver_item, null);
    }

    /**
     * 条目数据适配
     * @param view
     * @param data
     */
    public void setItem(final View view, final NewHomeOneBean.NewsPaperBean data) {
        TextView tag = (TextView) view.findViewById(R.id.jdContext);
        tag.setText(data.getContent());
        TextView stats = (TextView) view.findViewById(R.id.jdStats);
//        stats.setText("已有老师回答了此问题");
        TextView jdClick = (TextView) view.findViewById(R.id.jdClick);
//        jdClick.setText("5元");
//你可以增加点击事件
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String refType = data.getRef_type();
                String ref_id = data.getRef_id();
                if(TextUtils.isEmpty(refType)){
                    //return;
                    ToastUtil.showToast(context,"参数错误");
                }
                Intent intent;
                switch (refType) {
                    case "二手设备列表":
                        intent = new Intent(context, UsedSecondhandTypeActivity.class);
                        context.startActivity(intent);
                        break;
                    case "二手设备详情":
                        intent = new Intent(context, UsedMachineDetailActivity.class);
                        intent.putExtra("id", ref_id);
                        context.startActivity(intent);
                        break;
                    case "出租找活列表":
                        intent = new Intent(context, RentMachineNewActivity.class);
                        context.startActivity(intent);
                        break;
                    case "出租找活详情":
                        intent = new Intent(context, RentDetailActivity.class);
                        intent.putExtra("id", ref_id);
                        context.startActivity(intent);
                        break;
                    case "维修妙招列表":
                        intent = new Intent(context, IndurstryInformationActivity.class);
                        context.startActivity(intent);
                        break;
                    case "维修妙招详情":
                        intent = new Intent(context, IndustryInfoDetailActivity.class);
                        intent.putExtra("id", ref_id);
                        context.startActivity(intent);
                        break;
                    case "上门服务列表":
                        intent = new Intent(context, HomeServiceActivity.class);
                        context.startActivity(intent);
                        break;
                    case "上门服务详情":
                        intent = new Intent(context, HomeServiceDetailActivity.class);
                        intent.putExtra("id", ref_id);
                        context.startActivity(intent);
                        break;
                    case "工程师列表":
                        intent = new Intent(context, EngineerListActivity.class);
                        context.startActivity(intent);
                        break;
                    case "工程师详情":
                        intent = new Intent(context, EngineerDetailActivity.class);
                        intent.putExtra("id", ref_id);
                        context.startActivity(intent);
                        break;
                    case "商城列表":
                        NewWebActivity.start(context, "http://shop.jg969.com:90/client/index", "找配件", 1);
                        break;
                    case "商城详情":
                        NewWebActivity.start(context, ref_id, "商品详情", 0);//fengyi // bean.getShopDetailUrl()

                        break;
                }
            }
        });
    }

}
